from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

import twitter

class App(webapp.RequestHandler):

    def get(self):
        path = self.request.path
        if path=='/':
            self.__handle_home()
        user = path[1:]
        self.__handle_user(user)

    def __handle_home(self):
        pass

    def __handle_user(self, user):
        api = twitter.Api()
        statuses = api.GetUserTimeline(user, 101)
        has_more = len(statuses)>100
        if has_more:
            statuses = statuses[:-1]
        for s in statuses:
            self.response.out.write('<p><b>')
            self.response.out.write(s.user.name)
            self.response.out.write(':</b> ')
            self.response.out.write(s.text)
            self.response.out.write('</p>')

application = webapp.WSGIApplication([('^/.*$', App)], debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()
